<?php
/*
 * [JINYUN!] (C)2001-2099 Jinyunweb.com
 * This is NOT a freeware, use is subject to license terms
 *公告管理
*/
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'edit';
if($_RQ['op']=='edit'){
	//设置小程序基本信息
	if($_RQ['postdata']){
		$post=get_postdata();
		$id=intval($post['id']);
		$shownums=array(
			'news_num'=>intval($post['news_num']),
			'stores_num'=>intval($post['stores_num']),
			'products_num'=>intval($post['products_num']),
			'anlis_num'=>intval($post['anlis_num']),
		);
		$post['setting']['window']['navigationBarBackgroundColor']=$post['navigationBarBackgroundColor'];
		$post['setting']['window']['backgroundColor']=$post['backgroundColor'];
		$post['setting']['window']['backgroundColorTop']=$post['backgroundColorTop'];
		$post['setting']['window']['backgroundColorBottom']=$post['backgroundColorBottom'];
		$post['setting']['footer']['color']=$post['footercolor'];
		$post['setting']['footer']['selectedColor']=$post['footerselectedColor'];
		$post['setting']['footer']['backgroundColor']=$post['footerbackgroundColor'];
		$data=array(
			'title'=>trim($post['title']),
			'desc'=>trim($post['desc']),
			'logo'=>trim($post['logo']),
			'is_wz'=>intval($post['is_wz']),
			'appid'=>trim($post['appid']),
			'appsecret'=>trim($post['appsecret']),
			'tt_appid'=>trim($post['tt_appid']),
			'tt_secret'=>trim($post['tt_secret']),
			'ali_appid'=>trim($post['ali_appid']),
			'alipay_private_key'=>trim($post['alipay_private_key']),
			'alipay_public_key'=>trim($post['alipay_public_key']),
			'baidu_appid'=>trim($post['baidu_appid']),
			'baidu_secret'=>trim($post['baidu_secret']),
			'qq_appid'=>trim($post['qq_appid']),
			'qq_secret'=>trim($post['qq_secret']),
			'web_id'=>$post['web_id'],
			'oldid'=>$post['oldid'],
			'url'=>trim($post['url']),
			'shownums'=>ijson_encode($shownums),
			'setting'=>ijson_encode($post['setting']),
			'istabbar'=>intval($post['istabbar']),
			'sharetitle'=>trim($post['sharetitle']),
			'sharedesc'=>trim($post['sharedesc']),
			'shareimg'=>trim($post['shareimg']),
			'syscolor'=>$post['setting']['window']['navigationBarBackgroundColor'],
		);
		if(!$id){
			$data['uniacid']=$_SESSION['uniacid'];
			$data['type']=$_SESSION['wxapptype'];
			$data['plugin_name']='jy_liveshop';
			pdo_insert('core_account_wxapp',$data);
			$id=pdo_insertid();
			$live=pdo_get('core_account_wxapp_live',array('uniacid'=>$_SESSION['uniacid'],'pluginname'=>'jy_liveshop'));
			$live_id=$live['id'];
			if(!$live_id){
				pdo_insert('core_account_wxapp_live',array('wxapp_id'=>$id,'uniacid'=>$_SESSION['uniacid'],'pluginname'=>'jy_liveshop'));
			}
			exi('添加成功！');
		}else{
			$data['access_token']='';
			$data['expire']=0;
			$data['refresh_token']='';
			pdo_update('core_account_wxapp',$data,array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
			exi('设置成功！');
		}
		
	}else{
		$item=pdo_get('core_account_wxapp',array('uniacid'=>$_SESSION['uniacid'],'plugin_name'=>'jy_liveshop'));
		$item['shownums']=json_decode($item['shownums'],true);
		$setting =$item['setting'] ? json_decode($item['setting'],true):array('isfooter'=>0);
		$setting['window']=$setting['window']?$setting['window']:array('navigationStyle'=>'');
		$setting['footer']=$setting['footer']?$setting['footer']:array('background'=>'#fff');
		$setting['footer']['menus']=$setting['footer']['menus']?$setting['footer']['menus']:array();
		$setting['window']['navigationBarTitleText']=$setting['window']['navigationBarTitleText']?$setting['window']['navigationBarTitleText']:$item['title'];
		$setting['window']['navigationBarBackgroundColor']=$setting['window']['navigationBarBackgroundColor']?$setting['window']['navigationBarBackgroundColor']:'#f10215';
		$setting['window']['navigationBarTextStyle']=$setting['window']['navigationBarTextStyle']?$setting['window']['navigationBarTextStyle']:'white';
		$setting['window']['navigationStyle']=$setting['window']['navigationStyle']?:'custom';
		$item['navigationBarBackgroundColor'] = $setting['window']['navigationBarBackgroundColor'];
		$item['backgroundColor'] = $setting['window']['backgroundColor'];
		$item['backgroundColorTop'] = $setting['window']['backgroundColorTop'];
		$item['backgroundColorBottom'] = $setting['window']['backgroundColorBottom'];
		$item['footercolor']=$setting['footer']['color'];
		$item['footerselectedColor']=$setting['footer']['selectedColor'];
		$item['footerbackgroundColor']=$setting['footer']['backgroundColor'];
		$item['setting'] = $setting;
		$item['news_num']=$item['shownums']['news_num'];
		$item['stores_num']=$item['shownums']['stores_num'];
		$item['products_num']=$item['shownums']['products_num'];
		$item['anlis_num']=$item['shownums']['anlis_num'];
		$return['item']=$item;
		$return['navigationBarTextStyles'] =array('white'=>'white','black'=>'black');
		$return['backgroundTextStyles'] =array('dark'=>'dark','light'=>'light');
		$return['borderStyles'] =array('white'=>'white','black'=>'black');
		$return['positions'] =array('bottom'=>'bottom','top'=>'top');
		$return['navigationStyles'] =array('default'=>'开启','custom'=>'关闭');
		$return['iconstyle'] =array('0'=>'图片图标','1'=>'字体ICO图标');
		$htmls=array(
			'type'=>'edit',
			'desc'=>'小程序',
			'edit_tab'=>true,
			'edits'=>array(
				array(
					'title'=>'基本信息','list'=>array(
						array('type'=>'string','name'=>'title','title'=>'小程序名称','help'=>'小程序标题','must'=>true),
						array('type'=>'image','name'=>'logo','title'=>'小程序LOGO','help'=>'小程序LOGO'),
						array('type'=>'color_pool','name'=>'navigationBarBackgroundColor','title'=>'选择配色方案','help'=>''),
						array('type'=>'colorpicker','name'=>'navigationBarBackgroundColor','title'=>'小程序头底主色','help'=>''),
						array('type'=>'radio','name'=>'setting.window.navigationBarTextStyle','title'=>'导航栏标题颜色','options'=>'navigationBarTextStyles','option_value'=>'dtitle'),
						array('type'=>'phone_tpl','name'=>'navigationBarBackgroundColor','demo'=>1,'title'=>'演示效果'),
					),
				),
				array(
					'title'=>'六合一设置','list'=>array(
						array('type'=>'tip','title'=>'微信小程序参数设置；（要先去微信官网申请小程序，申请教程：<a href="javascript:;" ng-click="modal_json(\'core/wxapp.authlist/help/\')" class="btn btn-primary" style="padding:2px 6px;font-size:12px;">点击前往</a>）'),
						array('type'=>'string','title'=>'微信appid','name'=>'appid','help'=>'填写微信小程序appid' ),
						array('type'=>'string','title'=>'微信appsecret','name'=>'appsecret','help'=>'填写微信小程序 appsecret' ),
						array('type'=>'string','title'=>'原始ID','name'=>'oldid','help'=>'填写微信小程序原始ID'),
						array('type'=>'tip','title'=>'头条/抖音小程序参数设置'),
						array('type'=>'string','title'=>'头条/抖音appid','name'=>'tt_appid','help'=>'填写小程序appid' ),
						array('type'=>'string','title'=>'头条/抖音appsecret','name'=>'tt_secret','help'=>'填写小程序 appsecret' ),
						array('type'=>'tip','title'=>'支付宝小程序参数设置'),
						array('type'=>'string','title'=>'支付宝appid','name'=>'ali_appid','help'=>'填写小程序appid：支付宝开放平台：https://open.alipay.com/' ),
						array('type'=>'text','title'=>'支付宝应用私钥','name'=>'alipay_private_key','help'=>'支付宝开放平台创建应用成功后，进入应用设置(路径：开发中心—小程序应用—选择小程序-设置–开发设置)应用加签方式(<red>选择第二个“公钥”</red>)，设置应用公钥。使用密钥生成器(工具安装：https://opendocs.alipay.com/open/291/105971#Krqvg，选择：RSA2，PKCS1(非JAVA适用))生成一对密钥，将私钥填至此处，将公钥填于支付宝开放平台！'),
						array('type'=>'text','title'=>'支付宝公钥','name'=>'alipay_public_key','help'=>'成功设置应用私钥后，可以在同一个地方查看支付宝公钥，复制到此处！'),
						array('type'=>'tip','title'=>'百度小程序参数设置'),
						array('type'=>'string','title'=>'百度appid','name'=>'baidu_appid','help'=>'填写小程序appid' ),
						array('type'=>'string','title'=>'百度appsecret','name'=>'baidu_secret','help'=>'填写小程序 appsecret' ),
						array('type'=>'tip','title'=>'QQ轻应用参数设置'),
						array('type'=>'string','title'=>'QQ轻应用appid','name'=>'qq_appid','help'=>'填写小程序appid；前往QQ互联申请：https://connect.qq.com/'),
						array('type'=>'string','title'=>'QQ轻应用appkey','name'=>'qq_secret','help'=>'填写小程序 appkey；前往QQ互联申请：https://connect.qq.com/'),
					),
				),
				array(
					'title'=>'顶部导航设置','list'=>array(
						array('type'=>'radio','name'=>'setting.window.navigationStyle','read'=>'false','title'=>'是否关闭顶部导航','options'=>'navigationStyles','option_value'=>'dtitle','help'=>'<red>‘关闭导航’的情况下：顶部导航将启用系统自带的。而小程序本身自带的顶部导航等设置将失效，窗口样式，导航栏样式都将失效</red>。有些应用小程序，会被默认，<em>不能修改</em>。‘关闭’情况下只保留右上角胶囊按钮(‘关闭’情况下支持顶部图片背景)'),
						array('type'=>'image','name'=>'setting.window.navtop_bgimg','title'=>'导航栏背景图片','help'=>'导航栏为‘关闭’，才生效！尺寸：750*160；小程序顶部背景图片'),
						array('type'=>'radio','name'=>'setting.window.navigationBarTextStyle','title'=>'导航栏标题颜色','options'=>'navigationBarTextStyles','option_value'=>'dtitle'),
						array('type'=>'string','name'=>'setting.window.navigationBarTitleText','title'=>'导航栏标题','help'=>'导航栏标题文字内容！留空这使用小程序名称'),
					),
				),
				array(
					'title'=>'底部导航设置','list'=>array(
						array('type'=>'switch','name'=>'setting.isfooter','title'=>'是否开启导航','help'=>'如果是第三方小程序：1、必须先设置好第三方域名；1、从第三方登陆！'),
						array('type'=>'colorpicker','name'=>'footercolor','title'=>'文字默认颜色','help'=>'默认黑色'),
						array('type'=>'colorpicker','name'=>'footerselectedColor','title'=>'选中时的颜色','help'=>'默认绿色'),
						array('type'=>'colorpicker','name'=>'footerbackgroundColor','title'=>'导航的背景色','help'=>'默认白色'),
						array('type'=>'radio','name'=>'setting.footer.borderStyle','title'=>'边框的颜色','options'=>'borderStyles','option_value'=>'dtitle','help'=>'tabbar上边框的颜色， 仅支持 black / white'),
						array('type'=>'radio','name'=>'setting.footer.position','title'=>'TabBar的位置','options'=>'positions','option_value'=>'dtitle','help'=>'选择top的话，底部就不显示图片了，tabBar的位置，仅支持 bottom / top'),
						//array('type'=>'switch','name'=>'istabbar','title'=>'是开启小程序导航','help'=>'默认使用微官网自定义导航！'),
						array('type'=>'radio','name'=>'setting.footer.iconstyle','title'=>'启用ico图标？','options'=>'iconstyle','help'=>'默认使用图片图标，启用后就是ico图标！'),
						array('type'=>'switch','name'=>'setting.footer.islegao_menu','title'=>'全局底部菜单?','help'=>'开启后，本小程序所有页面的底部菜单，都以下面菜单为准！'),
						array('type'=>'tip','title'=>'[<red>底部菜单变化？</red>]：为了底部菜单的统一性，下面的菜单是跟DIY设计的时候的底部菜单是统一的，修改任何地方，都会同步变化！'),
						array(
								'type'=>'array',
								'name'=>'menus',
								'tovalue'=>'pagedata.item.setting.footer',
								//'show'=>array('istabbar'=>1),
								'add_tip'=>'添加一个底部导航',
									'list'=>array(
												array('type'=>'string','name'=>'title','title'=>'菜单名称'),
												array('type'=>'icon','name'=>'icon','from'=>'jinyunicon','title'=>'ICO图标'),
												array('type'=>'image','name'=>'iconimg','title'=>'图片图标'),
												array('type'=>'string','name'=>'url','title'=>'菜单链接'),
									),
									'details'=>array(
												array('type'=>'string','name'=>'title','title'=>'菜单名称'),
												array('type'=>'icon','name'=>'icon','from'=>'jinyunicon','title'=>'ICO图标'),
												array('type'=>'image','name'=>'iconimg','title'=>'图片图标'),
												array('type'=>'link','name'=>'url','from'=>'action','title'=>'菜单链接'),
												
									)
						),
					),
				),
				array(
						'title'=>'窗口样式设置','list'=>array(
							array('type'=>'colorpicker','name'=>'backgroundColor','title'=>'窗口的背景色','help'=>'默认白色，大部分不用填写！'),
							array('type'=>'radio','name'=>'setting.window.backgroundTextStyle','title'=>'窗口的背景色','options'=>'backgroundTextStyles','option_value'=>'dtitle'),
							array('type'=>'colorpicker','name'=>'backgroundColorTop','title'=>'顶部窗口的背景色','help'=>'顶部窗口的背景色，仅 iOS 支持,微信版本 6.5.16'),
							array('type'=>'colorpicker','name'=>'backgroundColorBottom','title'=>'底部窗口的背景色','help'=>'顶部窗口的背景色，仅 iOS 支持,微信版本 6.5.16'),
						),
					),
				array(
					'title'=>'分享设置','list'=>array(
						array('type'=>'string','name'=>'sharetitle','title'=>'小程序分享标题','help'=>'小程序分享标题'),
						array('type'=>'string','name'=>'sharedesc','title'=>'小程序分享描述','help'=>'小程序首页分享描述'),
						array('type'=>'image','name'=>'shareimg','title'=>'小程序分享图片','help'=>'小程序首页分享图片自定义，留空则默认截屏分享！'),
					),
				),
				array(
					'title'=>'直播插件设置','list'=>array(
						array('type'=>'switch','name'=>'setting.live.isopen','title'=>'是否开启小程序直播','help'=>'（<red>必须前往微信小程序官方--设置--第三方设置--插件管理--开通小程序直播插件，如果本小程序没有开通小程序直播插件，贸然开启，会导致小程序无法访问！同时无法上传发布小程序新版本！</red>）'),
						array('type'=>'string','name'=>'setting.live.version','title'=>'直播插件版本号','help'=>'微信官方小程序后台--》设置--第三方设置--插件--》直播插件，获取直播插件版本号；例如：1.0.2'),
						array('type'=>'string','name'=>'setting.live.provider','title'=>'直播插件id','help'=>'微信官方小程序后台--》设置--第三方设置--插件--》直播插件，获取直播插件id;例如：wx2b03c6e691cd7370'),
					),
				),
				array(
					'title'=>'其他全局设置','list'=>array(
						array('type'=>'switch','name'=>'setting.window.enablePullDownRefresh','title'=>'是否全局开启下拉刷新'),
						array('type'=>'string','name'=>'setting.window.onReachBottomDistance','title'=>'上拉触底距离','help'=>'只能填数字，默认50，页面上拉触底事件触发时距页面底部距离，单位为px'),
						array('type'=>'switch','name'=>'setting.window.no_location','title'=>'关闭地理位置相关接口','help'=>'关闭后地理位置接口失效，方便小程序审核通过！或者：<red>直接申请地理位置接口，只需带上获取位置的截图就可以过</red>！'),
					),
				),
			)
		);
		$return['htmls']=$htmls;
		exi($return);
	}
}
